package com.carefree.system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @ClassName:Knife4jConfig
 * @Description:
 * @Author Tengbin tengbin234@163.com
 */
@Configuration
// 3.0版本已废弃
//@EnableSwagger2WebMvc
public class Knife4jConfig {

    // 指定Controller包路径
    private String basePackage = "com.carefree.system.modules.admin.controller";
    //主机名
    private String host = "localhost";
    //标题
    private String title = "在线API文档";
    //简介
    private String description = "后台管理在线API文档";
    //服务条款URL
    private String termsOfServiceUrl = "http://tengbin1226.xyz";
    //联系人
    private String contactName = "小滕";
    // 联系网址
    private String contactUrl = "http://tengbin1226.xyz";
    // 联系邮箱
    private String contactEmail = "tengbin234@163.com";
    //版本号
    private String version = "1.0";

    @Bean(value = "dockerBean")
    public Docket dockerBean() {
        return new Docket(DocumentationType.SWAGGER_2)
                .host(host)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .termsOfServiceUrl(termsOfServiceUrl)
                .contact(new Contact(contactName, contactUrl, contactEmail))
                .version(version)
                .build();
    }

}
